package leetcode.L500;

public class Ex463 {
    public static void main(String[] args) {
        int[][] grid = {{0,1,0,0},
                       {1,1,1,0},
                       {0,1,0,0},
                       {1,1,0,0}};
        int m = grid.length;
        int n = grid[0].length;
        int ans = 0;
        int num = 0;

        for (int i = 0; i < m ; i++) {
            for (int j = 0; j < n ; j++) {
                if(grid[i][j]==1){
                    num++;
                    if(j+1<n&&grid[i][j+1]==1){
                        ans = ans +1;
                    }
                    if(i+1<m&&grid[i+1][j]==1){
                        ans = ans +1;
                    }
                }
            }

        }
        System.out.println(num*4-ans*2);
    }
}
